package inherit.practice.demo01;

import java.util.Random;

public class Role {
        private String name;
        private int blood;

        public Role() {
        }

        public Role(String name, int blood) {
                this.name = name;
                this.blood = blood;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public int getBlood() {
                return blood;
        }

        public void setBlood(int blood) {
                this.blood = blood;
        }

        public void attack(Role r){
                Random rd = new Random();
                int i = rd.nextInt(20)+1;
                // 数据结构就是血的一个下降
                int remainBlood = r.getBlood() - i;
                remainBlood = remainBlood < 0 ? 0 : remainBlood;
                r.setBlood(remainBlood);
                System.out.println(getName()+"攻击了"+r.getName()+","+r.getName()+"还剩"+r.getBlood()+"血。");
        }
}
